/*

Summary:
ListView class.

Remark:
Only supports report style currently.

Version:
0.0.2

LastUpdatedDate:
2012-10-27

CreatedDate:
2012-10-01

*/


#pragma once

#include "ControlWindow.h"
#include "..\..\Enum.h"



namespace Zaf {
namespace Mwl {
namespace __Internal {
	class WndProcPicker;
}



ZafEnum(ListViewHeaderStyle, DWORD) {
	Clickable,
	Nonclickable,
	None,
};



ZafEnum(ListViewSortingType, DWORD) {
	None,
	Ascending,
	Descending,
};



class ListView : public ControlWindow {

public:
	ListView();
	explicit ListView(WORD id);
	virtual ~ListView();

	ListViewHeaderStyle GetHeaderStyle() const;
	void SetHeaderStyle(ListViewHeaderStyle value);

	bool AlwaysShowSelection() const;
	void AlwaysShowSelection(bool value);

	bool IsSingleSelect() const;
	void IsSingleSelect(bool value);

	ListViewSortingType GetSortingType() const;
	void SetSortingType(ListViewSortingType value);

	bool IsFullRowSelect() const;
	void IsFullRowSelect(bool value);

	bool HasGridLines() const;
	void HasGridLines(bool value);

	int InsertColumn(const wchar_t* text, unsigned int width, int pos = -1);
	int InsertColumn(const std::wstring& text, unsigned int width, int pos = -1) { 
		InsertColumn(text.c_str(), width, pos);
	}

	bool DeleteColumn(int index);

	int GetColumnCount() const;

	int InsertItem(const wchar_t* text, int pos = -1);
	int InsertItem(const std::wstring& text, int pos = -1) {
		return InsertItem(text.c_str(), pos);
	}

	std::wstring GetItemText(int index, int subItem) const;

	void SetItemText(int index, int subItem, const wchar_t* text);
	void SetItemText(int index, int subItem, const std::wstring& text) {
		SetItemText(index, subItem, text.c_str());
	}

	bool DeleteItem(int index);

	int GetNextItemIndex(int pos = -1) const;
	int GetNextSelectedItemIndex(int pos = -1) const;

	int GetSelectedItemCount() const;
	int GetItemCount() const;

protected:
	LRESULT DefWndProc(const WndMsg& msg);

private:
	void CommonConstructor();

	HWND CreateConcreteWindow();

	bool HasListViewExtendedStyle(DWORD style) const;
	void ChangeListViewExtendedStyle(DWORD style, bool enable);

	static const wchar_t* const ClassName;
	static __Internal::WndProcPicker ListViewWndProc;

	unsigned int m_columnCount;
};



}
}